var htmlWebpackPlugin = require('html-webpack-plugin');
var path = require("path");
const ExtractTextPlugin = require("extract-text-webpack-plugin");
const webpack = require('webpack');
const UglifyJsPlugin = require('uglifyjs-webpack-plugin')

module.exports = {
	// 入口
	entry: {
		'main': './src/main.js',
		'vendors': ['vue', 'vue-router', 'moment', 'axios', 'vue-preview', 'vue-fancybox']
	},

	output: {
		path: __dirname + '/dist/',
		// 解决mui图标问题
		publicPath: '/',
		filename: './js/[name]-[hash].js'
	},
	module: {
		loaders: [{
			test: /\.js$/,
			loader: 'babel-loader',
			exclude: __dirname + '/node_modules/',
			include: [path.resolve(__dirname, '/src/')],
			query: {
				presets: ['env']
			}
		}, {
			test: /vue-preview.src.*?js$/,
			loader: 'babel-loader',
			query: {
				presets: ['env']
			}
		}, {
			test: /\.vue$/,
			loader: 'vue-loader' // vue-template-complier是内部代码的依赖
		}, {
			test: /\.css$/,
			//loader: 'style-loader!css-loader' /*!postcss-loader*/
			// 提取css插件
			use: ExtractTextPlugin.extract({
				fallback: "style-loader",
				use: "css-loader"
			})
		}, {
			test: /\.less$/,
			loader: 'style-loader!css-loader!postcss-loader!less-loader'
		}, {
			test: /\.html$/,
			loader: 'html-loader'
		}, {
			test: /\.tpl$/,
			loader: 'ejs-loader'
		}, {
			test: /\.(png|jpg|gif|svg|ttf|woff|woff2)$/i,
			loaders: [
				'url-loader?limit=1000&name=assets/[name]-[hash].[ext]',
				'image-webpack-loader'
			]
		}]
	},
	plugins: [
		new webpack.DefinePlugin({
			'process.env': {
				NODE_ENV: '"production"'
			}
		}),
		// 压缩混淆
		new UglifyJsPlugin(),
		//提取公共js
		new webpack.optimize.CommonsChunkPlugin({
			//使用者和第三方的关系
			names: ['vendors', 'manifest']
		}),
		//提取css, 设置名称
		new ExtractTextPlugin("css/styles-[contenthash].css"),
		new htmlWebpackPlugin({
			filename: 'index.html',
			template: './src/index.html',
			inject: 'body',
			favicon: path.resolve(__dirname, 'src/favicon.ico')
		})
	]
}